package com.me.modules.sys.controller;

import java.util.List;
import java.util.Map;

import com.me.modules.common.annotation.SysLog;
import com.me.modules.common.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.me.modules.sys.entity.FieldDictionaryEntity;
import com.me.modules.sys.service.FieldDictionaryService;
import com.me.modules.common.utils.PageUtils;
import com.me.modules.common.utils.Query;
import com.me.modules.common.utils.Result;


/**
 *
 *
 * @author me
 * @email me@163.com
 * @date 2018-12-17 16:48:00
 */
@RestController
@RequestMapping("/sys/fielddictionary")
public class FieldDictionaryController extends BaseController{
	@Autowired
	private FieldDictionaryService fieldDictionaryService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("fielddictionary:list")
	@SysLog("查询自定义扩展表单列表")
	public Result list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<FieldDictionaryEntity> fieldDictionaryList = fieldDictionaryService.queryList(query);
		int total = fieldDictionaryService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(fieldDictionaryList, total, query.getLimit(), query.getPage());

		return Result.ok().put("page", pageUtil);
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@SysLog("查询流程扩展表单")
	@RequiresPermissions("fielddictionary:info")
	public Result info(@PathVariable("id") Long id){
		FieldDictionaryEntity fieldDictionary = fieldDictionaryService.queryObject(id);

		return Result.ok().put("fieldDictionary", fieldDictionary);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@SysLog("保存流程扩展表单")
	@RequiresPermissions("fielddictionary:save")
	public Result save(@RequestBody FieldDictionaryEntity fieldDictionary){
		fieldDictionaryService.save(fieldDictionary);

		return Result.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("fielddictionary:update")
	@SysLog("修改流程扩展表单")
	public Result update(@RequestBody FieldDictionaryEntity fieldDictionary){
		fieldDictionaryService.update(fieldDictionary);

		return Result.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("fielddictionary:delete")
	@SysLog("删除流程扩展表单")
	public Result delete(@RequestBody Long[] ids){
		fieldDictionaryService.deleteBatch(ids);

		return Result.ok();
	}

}
